# -*- coding = utf-8 -*-
# @Time : 2023/8/28 20:40
# @Author : 龙王赘婿_彪少
# @File : ws_server.py
# @Software: PyCharm

# https://blog.csdn.net/captain5339/article/details/128212124

import asyncio
import websockets
from datetime import datetime


async def handler(websocket):
    data = await websocket.recv()
    reply = f"Data received as \"{data}\", time:{datetime.now()}"
    print(reply)
    await websocket.send(reply)
    print("send reply")


async def main():
    async with websockets.serve(handler, "localhost", 9999):
        await asyncio.Future()


if __name__ == "__main__":
    asyncio.run(main())